Skip to content

Docs: Add error handling section to submission handling docs #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

LeCarbonator
Copy link
Contributor

@LeCarbonator LeCarbonator commented Jun 8, 2025

  • React
  • Solid
  • Vue
  • Angular (Feedback appreciated)

This PR adds some code snippets to get users started on the three common types of errors:

  • Sync user errors
  • Async user errors
  • Server errors

The user errors are implemented using form / field validators (with links to the validation guide page). The Server error example is implemented using TanStack Query.

Comment on lines +46 to +49
if (response.isError) {
// Username is taken, return an error for the username field
return 'Username is already taken!'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says

return an error for the username field

but the error seems to go to the Form not to the Field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! The comment is kind of redundant now. I'll remove it!

onSubmit: async ({ value }) => {
// If an error happens, they are accessible through
// `createAccountMutation.error`
await createAccountMutation.mutateAsync(value)
Copy link
Contributor

@Pascalmh Pascalmh Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promoting "mutateAsync" here feels off:

you should almost always use mutate
– https://tkdodo.eu/blog/mastering-mutations-in-react-query#mutate-or-mutateasync

Suggested change
await createAccountMutation.mutateAsync(value)
createAccountMutation.mutate(value, {
onSuccess: () => {
// handle success by navigate to another route e.g.
}
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the thought process behind it:

  • Is mutate synchronous? If not, onSubmit would finish immediately and isSubmitting would flash true for a moment
  • Error handling informs TSF about isSubmitSuccessful, which would cause a disconnect if mutate errors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then this seems like one of those exceptions to not prefere mutate over mutateAsync ;-)

It's perfect as it is, thanks for clarifying!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you reckon this should be mentioned somewhere? I assume there's lots of users combining Tanstack Form with TansStack Query

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some explenation here: https://tanstack.com/form/latest/docs/reference/type-aliases/baseformstate#issubmitting

I think it would be good to mention it on the "Submission Handling"-Page as well as it clears up a lot of questions.

Pascalmh and others added 2 commits June 12, 2025 09:55
Signed-off-by: Pascal Küsgen <pascalkuesgen@gmail.com>
docs: expand submission handling in angular
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants